<?php

include_once('gridlayout.class.php');
include_once('myPDO.class.php');

class GridLayoutDAO {
    
    //Création d'un layout
    public function createGridLayout(/* GridLayout */ $gridLayout, /* myPDO */ $db) {

        try {
            $stmt = $db->prepare("INSERT INTO GridLayout (nbLignes, nbColonnes, Activite_idActi) VALUES (:lig, :col, :ida)");
            $lig = $gridLayout->getNbLignes();
            $col = $gridLayout->getNbColonnes();
            $id_acti = $gridLayout->getActiId();

            $stmt->bindParam(':lig', $lig);
            $stmt->bindParam(':col', $col);
            $stmt->bindParam(':ida', $id_acti);

            $stmt->execute();
        } catch (Exception $e) {
            echo 'Exception re�ue : ', $e->getMessage(), "\n";
        }
    }
    
    // Trouver un Grid Layout appartenant à une activité
    public function findGridLayout(/* Layout */ $layout, /* myPDO */ $db) {
        $stmt = $db->prepare("SELECT * FROM GridLayout WHERE Activite_idActi = :id ;");
        $id = $layout->getActiId();
        $stmt->bindParam(':id', $id);
        $res = $stmt->execute();
        $row = $stmt->fetchObject();
        if ($row == null) {
            return null;
        } else {
            //print_r($row);
            $layout = new GridLayout($row->identifiant, $row->nbLignes,$row->nbColonnes, $row->Activite_idActi);
            return $layout;
        }
    }
    
    // Spprimer un Grid Layout appartenant à une activité
    public function deleteGrid(/* Layout */ $layout, /* myPDO */ $db) {
        try {
            $stmt = $db->prepare("DELETE FROM GridLayout WHERE Activite_idActi = :id ;");
            $id = $layout->getActiId();
            $stmt->bindParam(':id', $id);
            $stmt->execute();
        } catch (Exception $e) {
            echo 'Exception re�ue : ', $e->getMessage(), "\n";
        }
    }

}

?>